﻿@using Website.Models
@model IEnumerable<Website.Models.Product>

@{
    ViewBag.Title = "Index";
}

@if(ViewBag.Message != null)
{
    <div style="color: red">@ViewBag.Message</div>
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
    @using (Html.BeginForm("Index","Product", FormMethod.Get))
    {
        <input type="text" id="productCode" name="productCode" value="@ViewBag.ProductCode"/> <input type="submit" value="Search By ProductCode"/>
    }
    @*@using (Html.BeginForm("DeleteByCategoryID","Product", FormMethod.Post))
    {
        <input type="text" id="catID" name="catID"/> <input type="submit" value="Delete By CategoryID"/>
    }*@
</p>
<table>
    <tr>
        <th>
            SmallImage
        </th>
        <th>
            ProductCode
        </th>
@*        <th>
            Price
        </th>*@
        <th>
            Category
        </th>
        <th>Quantity</th>
        <th>Size</th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            <img src="@Url.Content(item.SmallImage)" alt="@item.ProductCode" height="150px"/>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ProductCode)
        </td>
@*        <td>
            @Html.DisplayFor(modelItem => item.PriceLevel.Price)
        </td>*@
        <td>
            @Html.DisplayFor(modelItem => item.Category.CategoryName)
        </td>
        <td>
            @item.ProductSizes.Sum(p=>p.Quantity)
        </td>
        <td>
            @foreach(ProductSize ps in item.ProductSizes)
            {
                @ps.Size.SizeName @: : @ps.Quantity |
            }
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ProductID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ProductID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ProductID })
        </td>
    </tr>
}

</table>
